package com.coder.algorithm.leetcode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class l_0554 {

    public static void main(String[] args) {
        Solution solution = new Solution();
//        List<List<Integer>> list = create(new int[][]{
//                {1, 2, 2, 1},
//                {3, 1, 2},
//                {1, 3, 2},
//                {2, 4},
//                {3, 1, 2},
//                {1, 3, 1, 1}
//        });
        List<List<Integer>> list = create(new int[][]{
                {100000000},
                {100000000},
                {100000000}
        });
        int ans = solution.leastBricks(list);
        System.out.println("输出：" + ans);
    }

    private static List<List<Integer>> create(int[][] array) {
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < array.length; i++) {
            List<Integer> subList = new ArrayList<>();
            for (int j = 0; j < array[i].length; j++) {
                subList.add(array[i][j]);
            }
            list.add(subList);
        }
        return list;
    }

    static class Solution {

        public int leastBricks(List<List<Integer>> wall) {
            Map<Integer,Integer> map = new HashMap<>();
            int width = 0;
            for (List<Integer> list: wall) {
                width = 0;
                for (int i: list) {
                    width += i;
                    map.put(width, map.getOrDefault(width, 0) + 1);
                }
            }
            int counts = 0;
            for (Map.Entry<Integer,Integer> entry: map.entrySet()) {
                if (entry.getKey() != width) {
                    if (entry.getValue() > counts) {
                        counts = entry.getValue();
                    }
                }
            }
            return wall.size() - counts;
        }
    }
}
